<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>返回单元顺序相反的数组</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.array-reverse" class="refentry">
   <div class="refnamediv">
    <h1 class="refname">array_reverse</h1>
    <p class="verinfo">(PHP 4, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">array_reverse</span> &mdash; <span class="dc-title">
     返回单元顺序相反的数组
    </span></p>

   </div>
 <div class="refsect1 description" id="refsect1-function.array-reverse-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>array_reverse</strong></span>
    ( <span class="methodparam"><span class="type">array</span> <code class="parameter">$array</code></span>
   [, <span class="methodparam"><span class="type">bool</span> <code class="parameter">$preserve_keys</code><span class="initializer"> = <strong><code>FALSE</code></strong></span></span>
  ] ) : <span class="type">array</span></div>

    <p class="para rdfs-comment">
     <span class="function"><strong>array_reverse()</strong></span> 接受数组
     <code class="parameter">array</code> 作为输入并返回一个单元为相反顺序的新数组。
    </p>
  </div>

 <div class="refsect1 parameters" id="refsect1-function.array-reverse-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<code class="parameter">array</code></dt>

     <dd>

      <p class="para">
       输入的数组。
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">preserve_keys</code></dt>

     <dd>

      <p class="para">
       如果设置为 <strong><code>TRUE</code></strong> 会保留数字的键。
       非数字的键则不受这个设置的影响，总是会被保留。
      </p>
     </dd>

    
   </dl>

  </p>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-function.array-reverse-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   返回反转后的数组。
  </p>
 </div>
  
  <div class="refsect1 examples" id="refsect1-function.array-reverse-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-6063">
    <p><strong>Example #1 <span class="function"><strong>array_reverse()</strong></span> 例子</strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$input&nbsp;&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #DD0000">"php"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">4.0</span><span style="color: #007700">,&nbsp;array(</span><span style="color: #DD0000">"green"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"red"</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">$reversed&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">array_reverse</span><span style="color: #007700">(</span><span style="color: #0000BB">$input</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$preserved&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">array_reverse</span><span style="color: #007700">(</span><span style="color: #0000BB">$input</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$input</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$reversed</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$preserved</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
Array
(
    [0] =&gt; php
    [1] =&gt; 4
    [2] =&gt; Array
        (
            [0] =&gt; green
            [1] =&gt; red
        )

)
Array
(
    [0] =&gt; Array
        (
            [0] =&gt; green
            [1] =&gt; red
        )

    [1] =&gt; 4
    [2] =&gt; php
)
Array
(
    [2] =&gt; Array
        (
            [0] =&gt; green
            [1] =&gt; red
        )

    [1] =&gt; 4
    [0] =&gt; php
)
</pre></div>
    </div>
   </div>
  </p>
 </div>

 <div class="refsect1 seealso" id="refsect1-function.array-reverse-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="array_flip.html" class="function" rel="rdfs-seeAlso">array_flip()</a> - 交换数组中的键和值</span></li>
   </ul>
  </p>
 </div>

  </div></div></div></body></html>